

package com.dycong.common.json;

import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;

import java.util.List;

public class MySerializeConfig extends SerializeConfig {
	
	private List<Class<?>> baseClasses;
	
	private boolean hasBaseClass;
	
	public List<Class<?>> getBaseClasses() {
		return baseClasses;
	}

	public void setBaseClasses(List<Class<?>> baseClasses) {
		this.baseClasses = baseClasses;
	}

	public MySerializeConfig(List<Class<?>> list) {
		super();
		this.baseClasses = list;
		hasBaseClass=(list!=null && list.size()>0);
	}

	public ObjectSerializer getObjectWriter(Class<?> clazz) {
		ObjectSerializer writer;
		Class superClass=clazz.getSuperclass();
		if(hasBaseClass){
			for (Class tmpClazz : baseClasses) {
				if(superClass.equals(tmpClazz)){
					writer=(ObjectSerializer) new EnumSerializer(clazz);
					return writer;
				}
			}
		}
		writer = super.getObjectWriter(clazz);
        return writer;
        
    }
}
